import router from './router'
import './assets/css/global.css'
import { createApp } from 'vue'
import { ElButton, ElForm, ElInput, ElFormItem, ElMessage, ElContainer, ElHeader, ElAside, ElMain, ElMenu, ElSubmenu, ElMenuItem, ElMenuItemGroup, ElBreadcrumb, ElBreadcrumbItem, ElCard, ElRow, ElCol, ElTable, ElTableColumn, ElSwitch, ElTooltip, ElPagination } from 'element-plus'
import 'element-plus/lib/theme-chalk/index.css'
import App from './App.vue'
import axios from 'axios'

// 分页中文化
import locale from '../node_modules/element-plus/lib/locale/lang/zh-cn'

const app = createApp(App)
axios.defaults.baseURL = 'http://127.0.0.1:8888/api/private/v1/'

app.use(ElButton)
app.use(ElForm)
app.use(ElFormItem)
app.use(ElInput)
app.use(ElMessage)
app.use(ElContainer)
app.use(ElHeader)
app.use(ElAside)
app.use(ElMain)
app.use(ElMenu)
app.use(ElSubmenu)
app.use(ElMenuItem)
app.use(ElMenuItemGroup)
app.use(ElBreadcrumb)
app.use(ElBreadcrumbItem)
app.use(ElCard)
app.use(ElRow)
app.use(ElCol)
app.use(ElTable)
app.use(ElTableColumn)
app.use(ElSwitch)
app.use(ElTooltip)
app.use(ElPagination, locale)

axios.interceptors.request.use(config => {
  const tokenStr = window.sessionStorage.getItem('token')
  if (tokenStr) config.headers.Authorization = tokenStr
  return config
})

app.config.globalProperties.$http = axios
app.use(router).mount('#app')
